﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RedHouse.Web
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lnkLang.Click += new EventHandler(lnkLang_Click);
            lnkLocation.Click += new EventHandler(lnkLocation_Click);
            Session["location"] = Session["location"] == null ? 1 : Session["location"];

            if (Session["location"] == null || int.Parse(Session["location"].ToString()) == 1)
            {
                body.Attributes.Add("onload", "initializeHanoi()");
            }
            else
            {
                body.Attributes.Add("onload", "initializeHCM()");
            }
        }

        void lnkLocation_Click(object sender, EventArgs e)
        {
            if (Session["location"] == null || int.Parse(Session["location"].ToString()) == 1)
            {
                Session["location"] = 2;
                body.Attributes.Add("onload", "initializeHanoi()");
            }
            else
            {
                Session["location"] = 1;
                body.Attributes.Add("onload", "initializeHCM()");
            }
            Response.Redirect(string.Format("Home.aspx?location={0}", Session["location"].ToString()));
        }

        void lnkLang_Click(object sender, EventArgs e)
        {
            if (Session["Culture"].ToString() == "vi-VN")
            {
                //Session["Culture"] = "en-US";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                ///<remarks>
                ///Saving the current thread's culture set by the User in the Session
                ///so that it can be used across the pages in the current application.
                ///</remarks>
                Session["UICulture"] = Thread.CurrentThread.CurrentUICulture;
                Session["Culture"] = "en-US";
            }
            else
            {
                //Session["Culture"] = "vi-VN";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("vi-VN");
                Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");
                ///<remarks>
                ///Saving the current thread's culture set by the User in the Session
                ///so that it can be used across the pages in the current application.
                ///</remarks>
                Session["UICulture"] = Thread.CurrentThread.CurrentUICulture;
                Session["Culture"] = "vi-VN";
            }

            Response.Redirect(string.Format("Home.aspx?location={0}", Session["location"].ToString()));
        }
    }
}
